package com.huike.game.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.huike.game.R;
import com.huike.game.base.Game11;
import com.huike.game.dao.EnvironmentDao;
import com.huike.game.fragment.Game12TemFragment;
import com.huike.game.fragment.GameCqFragment;
import com.huike.game.fragment.GameHunFragment;
import com.huike.game.fragment.GameLightFragment;
import com.huike.game.fragment.GamePmFragment;
import com.huike.game.fragment.GameWayFragment;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

public class GameActivity12 extends AppCompatActivity {

    private ImageView iv_left_image;
    private TextView tv_left_text;
    private TextView tv_content_title;
    private ImageView iv_rigth_image;
    private TextView tv_right_text;
    private ViewPager vp_game12;
    private RadioGroup rg_game12;
    private RadioButton rb_game12;

    private List<Fragment> list;
    private RadioButton rb_game12_hum;
    private RadioButton rb_game12_pm;
    private RadioButton rb_game12_cq;
    private RadioButton rb_game12_light;
    private RadioButton rb_game12_way;
    private EnvironmentDao dao ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game12);

        try {
            dao = new EnvironmentDao(this);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        List<Game11.DataBean> query = dao.query();


        list = new ArrayList<>();
        list.add(new Game12TemFragment(query));
        list.add(new GameCqFragment());
        list.add(new GameHunFragment());
        list.add(new GamePmFragment());
        list.add(new GameWayFragment());
        list.add(new GameLightFragment());
        initView();

        vp_game12.setAdapter(new ViewsPager(getSupportFragmentManager()));

        rg_game12.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (i) {
                    case R.id.rb_game12:
                        vp_game12.setCurrentItem(0);
                        break;
                    case R.id.rb_game12_hum:
                        vp_game12.setCurrentItem(1);
                        break;
                    case R.id.rb_game12_pm:
                        vp_game12.setCurrentItem(2);
                        break;
                    case R.id.rb_game12_cq:
                        vp_game12.setCurrentItem(3);
                        break;
                    case R.id.rb_game12_light:
                        vp_game12.setCurrentItem(4);
                        break;

                    case R.id.rb_game12_way:
                        vp_game12.setCurrentItem(5);
                        break;
                }
            }
        });

        vp_game12.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        rb_game12.setChecked(true);
                        break;
                    case 1:
                        rb_game12_hum.setChecked(true);
                        break;
                    case 2:
                        rb_game12_pm.setChecked(true);
                        break;
                    case 3:
                        rb_game12_cq.setChecked(true);
                        break;
                    case 4:
                        rb_game12_light.setChecked(true);
                        break;
                    case 5:
                        rb_game12_way.setChecked(true);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void initView() {
        iv_left_image = (ImageView) findViewById(R.id.iv_left_image);
        tv_left_text = (TextView) findViewById(R.id.tv_left_text);
        tv_content_title = (TextView) findViewById(R.id.tv_content_title);
        iv_rigth_image = (ImageView) findViewById(R.id.iv_rigth_image);
        tv_right_text = (TextView) findViewById(R.id.tv_right_text);
        vp_game12 = (ViewPager) findViewById(R.id.vp_game12);
        rg_game12 = (RadioGroup) findViewById(R.id.rg_game12);
        rb_game12 = (RadioButton) findViewById(R.id.rb_game12);

        rb_game12_hum = (RadioButton) findViewById(R.id.rb_game12_hum);
        rb_game12_pm = (RadioButton) findViewById(R.id.rb_game12_pm);
        rb_game12_cq = (RadioButton) findViewById(R.id.rb_game12_cq);
        rb_game12_light = (RadioButton) findViewById(R.id.rb_game12_light);
        rb_game12_way = (RadioButton) findViewById(R.id.rb_game12_way);
        rb_game12.setChecked(true);


        iv_rigth_image.setVisibility(View.GONE);
        tv_right_text.setVisibility(View.GONE);

        tv_content_title.setText("实时数据");

        iv_left_image.setImageResource(R.drawable.tiao);
        tv_left_text.setVisibility(View.GONE);



    }

    class ViewsPager extends FragmentStatePagerAdapter {

        public ViewsPager(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }
    }

}

